package pers.bc.utils.aspect;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import pers.bc.utils.pub.LoggerUtil;

// @Component //将当前类注入到Spring容器内
// @Aspect //表明是一个切面类
public class AppMonitorRunAsp
{
    LoggerUtil logUtil = LoggerUtil.getInstance("aspectLogs");
    
    /** 日志調試h */
    // Boolean isDebug = Boolean.FALSE;
    public static Boolean isDebug = Boolean.TRUE;
    // Pointcut 切入点
    // com.gameley.dmgtpf.*.controller
    
    /*************************************************************
     * <br>
     *
     * 说明:定义切入点，切入点为com.xisoft.hr.controller下的所有函数 <br>
     *
     * @Description <br>
     * @Date Created on 2021/10/19 9:57 <br>
     * @Param [] <br>
     * @return void <br>
     * @Author LIBENCHENG
     * @version 1.0 <br>
     *************************************************************          <br>
     */
    @Pointcut("execution(public * com.yonyou.ucf.mdf (..))")
    public void logAspect()
    {
    }
    
    @Around("logAspect()")
    public Object deAround(ProceedingJoinPoint joinPoint) throws Throwable
    {
        logUtil.info("1、deAround");
        return joinPoint.proceed();
    }
    
    @Before("logAspect()")
    public void doBefore(JoinPoint joinPoint)
    {
        logUtil.info("2、doBefore");
    }
    
    @AfterReturning("logAspect()")
    public void doAfterReturning(JoinPoint joinPoint)
    {
        logUtil.info("3、doAfterReturning");
    }
    
    @After("logAspect()")
    public void doAfter(JoinPoint joinPoint)
    {
        logUtil.info("4、doAfter");
    }
    
    @AfterThrowing(pointcut = "logAspect()", throwing = "e")
    public void doAfterThrowing(JoinPoint point, Throwable e)
    {
        logUtil.exception("2.5、deAfterThrowing", e);
    }
    
    /**
     * 获取注解中对方法的描述信息 用于Controller层注解
     *
     * @param joinPoint 切点
     * @return 方法描述
     * @throws Exception
     */
    @SuppressWarnings("rawtypes")
    public Map<String, Object> getControllerMethodDescription(JoinPoint joinPoint) throws Exception
    {
        Map<String, Object> map = new HashMap<String, Object>();
        String targetName = joinPoint.getTarget().getClass().getName();
        String methodName = joinPoint.getSignature().getName();
        Object[] arguments = joinPoint.getArgs();
        Class targetClass = Class.forName(targetName);
        Method[] methods = targetClass.getMethods();
        
        return map;
    }
    
}
